import request from '/@/utils/request';
import qs from 'qs'


/**
 * （不建议写成 request.post(xxx)，因为这样 post 时，无法 params 与 data 同时传参）
 *
 * 登录api接口集合
 * @method signIn 用户登录
 * @method signOut 用户退出登录
 */
export function useLoginApi() {
	return {
		signIn: (data: object) => {
			let params = qs.stringify(data);
			return request({
				url: 'auth/login',
				method: 'post',
				data: params,
				headers: {
					"Content-Type": "application/x-www-form-urlencoded",
				}
			});
		},
		signOut: (token: any) => {
			return request({
				url: '/auth/logout',
				method: 'post',
				headers: {
					"Authorization": token,
				}
			});
		},

		/**
		 * 获取验证码
		 * @param type 
		 * @returns 
		 */
		verifyCodeGenerator: (type: number) => {
			return request({
				url: `COMMON-SERVICE/user/verify/generate/${type}`,
				method: 'get'
			})
		},

		/**
		 * 获取用户登录信息
		 * @returns 
		 */
		getInfo: () => {
			return request({
				url: `user/info/authentication`,
				method: 'get'
			})
		},

		/**
		 * 修改登录密码
		 * @param oldPassword 旧密码
		 * @param newPassword 新密码
		 * @returns 
		 */
		updatePassWord: (oldPassword: any, newPassword: any) => {
			return request({
				url: `COMMON-SERVICE/userinfo/updatePassWord?oldPassword=${oldPassword}&newPassword=${newPassword}`,
				method: 'get'
			})
		},

		/**
		 * 检查是否绑定了谷歌验证码
		 * @returns 
		 */
		checkUserGoogleSecretBindStatus: () => {
			return request({
				url: `COMMON-SERVICE/user/mfa/checkUserGoogleSecretBindStatus`,
				method: 'get'
			})
		},

		/**
		 * 绑定用户的谷歌
		 * @param googleCode 
		 * @returns 
		 */
		bindUserGoogleSecret: (googleCode: any) => {
			return request({
				url: `COMMON-SERVICE/user/mfa/bindUserGoogleSecret`,
				headers: {
					"x-header-mfa-value": googleCode
				},
				method: 'get'
			})
		},


		/**
		 * 检查用户的谷歌
		 * @param googleCode 
		 * @returns 
		 */
		checkCurrentUserGoogleCode: (googleCode: any) => {
			return request({
				url: `COMMON-SERVICE/user/mfa/checkCurrentUserGoogleCode/${googleCode}`,
				method: 'get'
			})
		},


		/**
		 * 管理员修改用户密码
		 * @param id 
		 * @param newPassword 
		 * @returns 
		 */
		updatePassWordByAdmin: (id: any, newPassword: any) => {
			return request({
				url: `COMMON-SERVICE/userinfo/updatePassWordByAdmin?id=${id}&newPassword=${newPassword}`,
				method: 'get'
			})
		},

		/**
		 * 是否开启了验证telCode
		 * @returns 
		 */
		isOpenTelegramValidateCode: () => {
			return request({
				url: `COMMON-SERVICE/user/mfa/isOpenTelegramValidateCode`,
				method: 'get'
			})
		},

		/**
		 * 获取telegram验证码
		 * @param operate  LOGIN,MODIFY_LOGIN_LOCKER_IP,OTHER_MUST_LOGIN,OTHER_NO_LOGIN
		 * @param userName 
		 * @returns 
		 */
		getTelegramValidateCode: (operate: any, userName: any) => {
			return request({
				url: `/COMMON-SERVICE/user/mfa/getTelegramValidateCode?operate=${operate}&userName=${userName}`,
				method: 'get'
			})
		},

		/**
		 * 修改IP地址登录的限制
		 * @param data 
		 * @returns 
		 */
		changeLoginIp: (data: any) => {
			return request({
				url: `/COMMON-SERVICE/app/userRef/changeLoginIp`,
				data,
				method: 'post'
			})
		},

		/**
		 * 获取当前请求的IP
		 * @returns 
		 */
		getCurrentIp: () => {
			return request({
				url: `/COMMON-SERVICE/app/userRef/getCurrentIp`,
				method: 'post'
			})
		},


		/**
		 * 校验用户的google验证码
		 * @param data 
		 * @returns 
		 */
		checkUserGoogleCode: (data: any) => {
			let params = qs.stringify(data);
			return request({
				url: `/MANA3-SERVICE/admin/user/checkUserGoogleCode?${params}`,
				method: 'get'
			})
		},




	};
}
